package huaweiod.third;

import java.util.*;

/**
 * 五子棋迷
 * https://blog.csdn.net/qfc_128220/article/details/130766999
 */
public class B_GoziFan {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int color = Integer.parseInt(in.nextLine());
        int[] arr = Arrays.stream(in.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int left = 0;
        int right = 1;
        int zeroCount = 0;
        int count = 0;
        int ansIndex = -1;
        int maxCount = 0;
        if (arr[0] == color) {
            maxCount = 1;
            count = 1;
        } else if (arr[0] == 0) {
            zeroCount = 1;
            maxCount = 1;
            ansIndex = 0;
            count = 1;
        } else {
            left = 1;
        }
        int tempIndex = -1;
        List<Integer> ans = new ArrayList<>();
        while (right < arr.length) {
            if (count == 5) {
                if (arr[left] == 0) {
                    zeroCount--;
                }
                left++;
                count--;
            }
            if (arr[right] == color) {
                right++;
                count++;
            } else if (arr[right] == 0) {
                tempIndex = right;
                if (zeroCount == 1) {
                    while (arr[left] != 0) {
                        left++;
                        count--;
                    }
                    left++;
                    count--;
                } else {
                    zeroCount++;
                }
                right++;
                count++;
            } else {
                left = right + 1;
                right++;
                count = 0;
                zeroCount = 0;
            }

            if (count > maxCount) {
                maxCount = count;
                ansIndex = tempIndex;
                ans.clear();
            }
            if (count == maxCount) {
                ans.add(tempIndex);
            }
        }
//        System.out.println(ans);
        int res = Integer.MAX_VALUE;
        int temp = -1;
        for (Integer cur : ans) {
            if (Math.abs(cur - (arr.length - 1) / 2) < res) {
                res = Math.abs(cur - (arr.length - 1) / 2);
                temp = cur;
            }
        }
        System.out.println(temp);
    }
}